<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use think\Db;

class IndexController extends HomeBaseController
{
    public function index()
    {
        return $this->fetch(':index');
    }

    public function record()
    {
        $list=[];
       for($i=0;$i<=2;$i++){
           if($i==0){
               $begin_time = date ( "Y-m-d H:i:s", mktime ( 0, 0, 0, date ( "m" ), 1, date ( "Y" ) ) );
               $end_time = date ( "Y-m-d H:i:s", mktime ( 23, 59, 59, date ( "m" ), date ( "t" ), date ( "Y" ) ) );
           }elseif($i==1){
               $begin_time = date('Y-m-01 00:00:00',strtotime('-1 month'));
               $end_time = date("Y-m-d 23:59:59", strtotime(-date('d').'day'));
           }elseif($i==2){
               $begin_time =  date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-2,1,date("Y")));
               $end_time =  date("Y-m-d H:i:s",mktime(23,59,59,date("m")-1 ,0,date("Y")));
           }
           $b_time=date('y-m',strtotime($begin_time));
           $where['post_status']=1;
           $where['published_time'] = array('between',[strtotime($begin_time),strtotime($end_time)]);
           $join=[['__PORTAL_CATEGORY_POST__ p','p.id=a.parent_id','LEFT']];
           $field='a.id,a.post_status,a.published_time,a.post_title,a.parent_id,p.category_id';
           $list[$b_time]=Db::name('portal_post')->alias('a')->join($join)->where($where)->order('id desc')->field($field)->select();
       }

        $this->assign('list', $list);
        return $this->fetch(':record');
    }
    public function guestbook()
    {
        return $this->fetch(':guestbook');
    }

    public function side(){
        $num=Db::name('portal_post')->count();
        $this->assign('num', $num);
    }
}
